home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 July / EnigmA AMIGA RUN 09 (1996)(G.R. Edizioni)(IT)[!][issue 1996-07 & 08][EARSAN CD VIII].iso / earcd / util3 / wat.lha / WAT next >
Text File  |  1996-06-03  |  9KB  |  188 lines

  1. /* What?! Another Timer?! Version 1.00 */
  2. /* Copyright © Michael Tanzer 1996 */
  3. /* See additional notices in accompanying documentation */
  4. blanks = 0 /* Number of blank lines at the top of the window.   */
  5.            /* If you use a screen text font that is larger than */
  6.            /* 9 pixels in height, you may need to increase this */
  7.            /* value (by 1 or 2) for cosmetic purposes.          */
  8.  
  9. arg nport .           /* Notify port   */
  10.  
  11. /* Make sure the necessary functions are available */
  12. if ~show('l','rexxsupport.library') then
  13.   call addlib('rexxsupport.library',0,-30)
  14. if ~show('l','rexxarplib.library') then
  15.   call addlib('rexxarplib.library',0,-30)
  16. signal on syntax
  17.  
  18. /* Run WAT asynchronously */
  19. w = getclip('WAT')                        /* See if we've been here     */
  20. if w~=1 then do                           /* Nope, initialise           */
  21.   parse source mode .                     /*   COMMAND or FUNCTION?     */
  22.   w = getnport(nport)                     /*   Go verify port name      */
  23.   if w~=1 then do                         /*   Handle error             */
  24.     if mode='COMMAND' then exit w
  25.     return 0
  26.     end
  27.   call setclip('WAT',1)                   /*   Mark the trail           */
  28.   address arexx 'WAT' nport               /*   Run asynchronously       */
  29.   if mode='COMMAND' then exit
  30.   return 1
  31.   end
  32. call setclip('WAT')                       /* Clear flag                 */
  33.  
  34. /* Get name for control port */
  35. cport = nport'CTL'
  36. if showlist('p',cport) then call exit(cport)
  37.  
  38. /* Set some rather important variables */
  39. cfgfile = 'S:WAT.config'
  40.  
  41. idcmp = 'closewindow+gadgetup+menupick'
  42. flags = 'windowclose+windowdrag+windowdepth'
  43.  
  44. xchar  = 8            /* Pixels / col  */
  45. ychar  = 9            /* Pixels / row  */
  46. yoff   = ychar*blanks /* Blank lines   */
  47.  
  48. wx  = 0               /* Window left   */
  49. wy  = 0               /* Window top    */
  50. ww  = 168             /* Window width  */
  51. wh  = 59+yoff         /* Window height */
  52. stx = 18              /* START left    */
  53. sty = 14+yoff         /* START top     */
  54. spx = 114             /* STOP  left    */
  55. spy = 14+yoff         /* STOP  top     */
  56.  
  57. /* Read config file */
  58. w = open('input',cfgfile,'r')             /* Open config file as input   */
  59. if w=1 then do                            /* Proceed if file found       */
  60.   w = readln('input')                     /*   Read 1st record           */
  61.   do while ~eof('input')                  /*   Loop through rest of file */
  62.     interpret w                           /*     Interpret this record   */
  63.     w = readln('input')                   /*     Read next record        */
  64.     end
  65.   call close 'input'                      /*   Close config file         */
  66.   end
  67.  
  68. /* Set up host environment, window, etc. */
  69. startsecs = time('s')                     /* Set start time              */
  70. stopsecs  = time('s')                     /* Set stop time               */
  71. call openport(nport)                      /* Open notify port            */
  72. address arexx "'call createhost("cport","nport")'"/* Open control port   */
  73. address command 'WAITFORPORT' cport       /* Note: fall through on error */
  74. call openw                                /* Go open new window          */
  75. call showtime                             /* Go show the time            */
  76. flags = flags'+activate'                  /* Adjust for preferences      */
  77.  
  78. /* Main control loop */
  79. halt: do forever                          /* Top of main control loop    */
  80.   signal on halt                          /* HI causes return to top     */
  81.   trace 'b'                               /* Continue in spite of TS     */
  82.   call waitpkt(nport)                     /* Wait for some action        */
  83.   pkt = getpkt(nport)                     /* Retrieve packet             */
  84.   if pkt=='00000000'x then iterate        /* Caused by TS                */
  85.   message = getarg(pkt)                   /* Retrieve message            */
  86.   call reply(pkt,0)                       /* Acknowledge message         */
  87.   action = upper(word(message,1))         /* Isolate 1st word of msg     */
  88.   select                                  /* Respond as required         */
  89.     when action=='QUIT' then leave        /* QUIT chosen from menu       */
  90.     when action=='CLOSEWINDOW' then leave /* Window closed               */
  91.     when action=='START' then do          /* START gadget                */
  92.       startsecs = time('s')               /*   Reset start time          */
  93.       stopsecs = startsecs                /*   Reset stop time           */
  94.       end /* START */
  95.     when action=='STOP' then do           /* STOP gadget                 */
  96.       stopsecs = time('s')                /*   Get stop time             */
  97.       end /* STOP */
  98.     when action=='SPREF' then do          /* SAVE PREFS chosen from menu */
  99.       if words(message)>2 then do         /*   Check for window position */
  100.         wx = word(message,2)              /*     Save window x           */
  101.         wy = word(message,3)              /*     Save window y           */
  102.         end
  103.       w = statef(cfgfile)                 /*   See if cfg file exists    */
  104.       if w='' then call delete cfgfile    /*   If so, delete it          */
  105.       call open 'output',cfgfile,'w'      /*   Open config file as output*/
  106.       if result then do                   /*   Proceed if open ok...     */
  107.         w = 'wx =' wx                     /*     Window left             */
  108.         call writeln 'output',w
  109.         w = 'wy =' wy                     /*     Window top              */
  110.         call writeln 'output',w
  111.         call close 'output'               /*     Close output file       */
  112.         msg = 'Preferences saved.'        /*     Build success message   */
  113.         end
  114.       else msg = 'Unable to write\'cfgfile/*   ...or build error message */
  115.       call postmsg(0,0,msg)               /*   Post the message          */
  116.       call delay 100                      /*   Wait a couple seconds     */
  117.       call postmsg()                      /*   Clear the message         */
  118.       iterate                             /*   Bypass refresh            */
  119.       end /* SPREF */
  120.     otherwise iterate                     /* Ignore unknown actions      */
  121.     end /* select */
  122.   call showtime                           /* Show the elapsed time       */
  123.   end /* Main control loop */
  124.  
  125. /* Clean up and get out */
  126. syntax: signal off syntax                 /* Clear for next two calls    */
  127. call exit(cport)                          /* Close window, remove host   */
  128. call closeport(nport)                     /* Close notify port           */
  129. exit                                      /* Ride off into the sunset    */
  130.  
  131. showtime:                                 /* Show the elapsed time       */
  132.   if stopsecs>=startsecs then,            /* Get elapsed time            */
  133.     elapsed = stopsecs-startsecs
  134.   else elapsed = stopsecs+86400-startsecs /* Handle midnight crossing    */
  135.   text = left('\',blanks,'\')   ||,       /* Adjust for large font       */
  136.   '\Start   'gettime(startsecs) ||,       /* Get start time              */
  137.   '\Stop    'gettime(stopsecs)  ||,       /* Get stop time               */
  138.   '\Elapsed 'gettime(elapsed)             /* Get elapsed time            */
  139.   call windowtext(cport,text)             /* Write time                  */
  140.   return
  141.  
  142. gettime:
  143.   arg s                                   /* Get seconds                 */
  144.   hh = right(s%3600,2,'0')                /* Get hours                   */
  145.   w = s//3600
  146.   mm = right(w%60,2,'0')                  /* Get minutes                 */
  147.   w = w//60
  148.   ss = right(w%1,2,'0')                   /* Get seconds                 */
  149.   time = hh':'mm':'ss                     /* Format time                 */
  150.   return time
  151.  
  152. openw:                                    /* Open a window               */
  153.   w = screencols('Workbench')
  154.   if wx+ww>w then wx = w-ww
  155.   w = screenrows('Workbench')
  156.   if wy+wh>w then wy = w-wh
  157.   call openwindow(cport,wx,wy,ww,wh,idcmp,flags,nport)
  158.   call addmenu(cport,left(nport,8))
  159.   call additem(cport,'Save prefs   ','spref %f %e')
  160.   call additem(cport,'Quit         ','quit')
  161.   call addgadget(cport,stx,sty,'start','Start','start')
  162.   call addgadget(cport,spx,spy,'stop','Stop','stop')
  163.   call setitem(cport,0,1,0,'on')
  164.   return
  165.  
  166. /* Get notify port name */
  167. getnport:
  168.   if nport='HELP' | nport='?' then do
  169.     say 'Format: WAT <portname>'
  170.     exit
  171.     end
  172.   if words(nport)=0 then do
  173.     nport = 'WAT'
  174.     w = 1
  175.     if showlist('p','WAT') then do forever
  176.       nport = 'WAT'w
  177.       if ~showlist('p',nport) then leave
  178.       w = w+1
  179.       end
  180.     end
  181.   else do
  182.     if showlist('p',nport) then do
  183.       say 'Port' nport 'already in use.'
  184.       return 99
  185.       end
  186.     end
  187.   return 1
  188.